package lab03.test04;

import java.io.*;

public class Test {
    public static void main(String[] args) {


        /**
         * 通过字节流读写文件实现文件的拷贝
         */

        String path1 = "D:\\dev\\lab03\\source\\Hello.txt";
        String path2 = "D:\\dev\\lab03\\target\\Hello.txt";

        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;

        try {
            fileInputStream = new FileInputStream(path1);
            fileOutputStream = new FileOutputStream(path2);

            int data;

            //读一个字节 马上写一个字节
            while ((data = fileInputStream.read()) != -1) {

                fileOutputStream.write(data);
            }
        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();
        } finally {
            //最后关闭文件
            try {

                fileInputStream.close();
            } catch (IOException e) {

                e.printStackTrace();
            }
            try {

                fileOutputStream.close();
            } catch (IOException e) {

                e.printStackTrace();
            }

        }
        System.out.println("文件拷贝完成！");
    }
}
